﻿using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using LRS.DAL;

public static class dManufacturer
{
    public static List<eManufacturer> GetManufacturers()
    {
        List<eManufacturer> manufacturers = new List<eManufacturer>();
        SqlDataReader reader = SqlHelper.ExecuteReader("Select * from Manufacturer Order by ManuName ASC");
        while (reader.Read())
        {
            eManufacturer man = new eManufacturer();
            man.ManufacturerID = Int32.Parse(reader["ManuID"].ToString());
            man.ManufacturerName = reader["ManuName"].ToString();
            man.ManufacturerNumber = reader["ManufacturerNumber"].ToString();
            man.ContactAddress = reader["ContactAddress"].ToString();
            man.ContactEmail = reader["ContactEmail"].ToString();
            man.ContactPhone = reader["ContactPhone"].ToString();
            manufacturers.Add(man);
        }
        reader.Close();
        return manufacturers;
    }
    public static eManufacturer GetManufacturerByID(int ID)
    {
        SqlDataReader reader = SqlHelper.ExecuteReader("Select * from Manufacturer where ManuID=" + ID.ToString());
        reader.Read();
        eManufacturer man = new eManufacturer();
        man.ManufacturerID = Int32.Parse(reader["ManuID"].ToString());
        man.ManufacturerName = reader["ManuName"].ToString();
        man.ManufacturerNumber = reader["ManufacturerNumber"].ToString();
        man.ContactAddress = reader["ContactAddress"].ToString();
        man.ContactEmail = reader["ContactEmail"].ToString();
        man.ContactPhone = reader["ContactPhone"].ToString();

        reader.Close();
        return man;
    }

    public static void InsertManufacturer(eManufacturer man)
    {
        List<SqlParameter> parameters = new List<SqlParameter>();
        parameters.Add(new SqlParameter("@ManuName", man.ManufacturerName));
        parameters.Add(new SqlParameter("@ContactAddress", man.ContactAddress));
        parameters.Add(new SqlParameter("@ContactEmail", man.ContactEmail));
        parameters.Add(new SqlParameter("@ContactPhone", man.ContactPhone));
        SqlHelper.ExecuteNonQuery("Insert into Manufacturer values(@ManuName, @ContactAddress, @ContactEmail, @ContactPhone)", parameters);
    }
    public static void UpdateManufacturer(eManufacturer man)
    {
        List<SqlParameter> parameters = new List<SqlParameter>();
        parameters.Add(new SqlParameter("@ManuName", man.ManufacturerName));
        parameters.Add(new SqlParameter("@ContactAddress", man.ContactAddress));
        parameters.Add(new SqlParameter("@ContactEmail", man.ContactEmail));
        parameters.Add(new SqlParameter("@ContactPhone", man.ContactPhone));
        parameters.Add(new SqlParameter("@ManufacturerID", man.ManufacturerID));
        SqlHelper.ExecuteNonQuery("Update Manufacturer set ManuName=@ManuName, ContactAddress=@ContactAddress, ContactEmail=@ContactEmail, ContactPhone=@ContactPhone Where ManuID=@ManufacturerID", parameters);
    }
    public static void DeleteManufacturerByID(int ManuID)
    {
        SqlHelper.ExecuteNonQuery("Delete from Manufacturer where ManuID = " + ManuID);
    }
}
